package main

import (
	"github.com/gin-gonic/gin"
	log "github.com/micro/go-micro/v2/logger"
	"github.com/micro/go-micro/v2/web"

	"github.com/morphyguo/demo/commons/setting"
	"github.com/morphyguo/demo/web/blog/models"
	"github.com/morphyguo/demo/web/blog/pkg/gredis"
	"github.com/morphyguo/demo/web/blog/routers"
	"strconv"
)

func main() {

	setting.Setup()
	models.Setup()
	gredis.Setup()
	service := web.NewService(
		web.Name(setting.AppSetting.Name),
		web.Address(":"+strconv.Itoa(setting.ServerSetting.HttpPort)),
	)
	service.Init()
	gin.SetMode(setting.ServerSetting.RunMode)
	routersInit := routers.InitRouter()
	log.Info("[info] start http server listening %s", strconv.Itoa(setting.ServerSetting.HttpPort))
	service.Handle("/", routersInit)
	if err := service.Run(); err != nil {
		log.Fatal(err)
	}
}